package org.coding.springbootdemocommandline.beandefinition;

import org.coding.springbootdemocommandline.beandefinition.entity.Person;
import org.coding.springbootdemocommandline.beandefinition.entity.User;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.ChildBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * ^ enjoy coding and be bugfree boy
 *
 * @author guoxh
 * @date 2020/11/16 5:24 下午
 * @desc
 **/
public class BeanDefinitionInheritApp {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext configApplicationContext = new AnnotationConfigApplicationContext();
        configApplicationContext.register(BeanDefinitionInheritApp.class);

        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.add("name","荆轲");
        mutablePropertyValues.add("code","jingke");
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(User.class,null,mutablePropertyValues);
        configApplicationContext.registerBeanDefinition("user",rootBeanDefinition);
        //configApplicationContext.refresh();

        ChildBeanDefinition childBeanDefinition = new ChildBeanDefinition("user");
        childBeanDefinition.setBeanClass(Person.class);
        childBeanDefinition.getPropertyValues().add("nickName","李白");
        configApplicationContext.registerBeanDefinition("person",childBeanDefinition);
        configApplicationContext.refresh();

        User user = configApplicationContext.getBean(User.class);
        Person person = configApplicationContext.getBean(Person.class);

        System.out.println(user);
        System.out.println(person);
    }
}
